/*
 * 作者: 侯晓宇
 * 时间: 2017-03-11 
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	
	require("jquery");

	var c = require('app/utils/CommonUtils');
	var appInfo = require('app/AppInfo');
	var hc = require('app/utils/HttpClientUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var param = api.pageParam;
	var user = UserInfoUtils.getLoginedUser();
	
	var coverurl = param.coverurl;
	var teststreamid = param.teststreamid;
	var prostreamid = param.prostreamid;
	var roomuuid = param.roomuuid;
	var clipBoard = api.require('clipBoard');
	
	
	
	$("#back").click(function(){
		api.closeWin({
	    });
	});
	
	var url = appInfo.serverbase + "/luyan/room_details";
	var body = {};
	body.roomid = param.roomuuid;
	body.userid = user.userid;
	
	hc.post(url,body,function(resp){
		
		if(resp.status == "200"){
			
			$("#roomname").html(resp.result.name);
			$("#ops").show();
			
			var page = resp.result.pages[0];
			var value = page.publishurl;

			var publishid = page.publishid;
			var thumburl = page.thumburl;
			
			if(c.isNullStr(thumburl)){
				if(publishid == param.teststreamid){
					$("#livestatus").html("试播状态");
				}else if(publishid == param.prostreamid){
					$("#livestatus").html("正式直播状态");
				}
				
				$("#publishurl").val(page.publishurl);
				clipBoard.set({
				    value: value
				}, function(ret, err) {
				    if (ret) {
				    	api.toast({
			                msg:'已将推流地址保存至剪贴板'
		                });
				    } else {
		
				    }
				});
			}else{
				$("#livestatus").html("预告状态");
			}
			
		}
	
	});
	
	$("#preview").click(function(){
		var url = appInfo.serverbase + "/luyan/stream/room/"+param.roomuuid+"/switch";
		var body = {};
		body.streamid = "";
		body.coverurl = coverurl;
		hc.post(url,body,function(resp){
			
			if(resp.status == "200"){
				location.reload();
			}
		
		});
	});
	
	$("#test").click(function(){
		var url = appInfo.serverbase + "/luyan/stream/room/"+param.roomuuid+"/switch";
		var body = {};
		body.streamid = param.teststreamid;
		body.coverurl = "";
		hc.post(url,body,function(resp){
			
			if(resp.status == "200"){
				location.reload();
			}
		
		});
	});


	$("#pro").click(function(){
		var url = appInfo.serverbase + "/luyan/stream/room/"+param.roomuuid+"/switch";
		var body = {};
		body.streamid = param.prostreamid;
		body.coverurl = "";
		hc.post(url,body,function(resp){
			
			if(resp.status == "200"){
				location.reload();
			}
		
		});
	});


	return;
});